// Figure 2b: Support for Barack Obama
// Andrew Gooch
// Yale University
// July 2018

// CREATE OVERALL TREATMENT EFFECT PLOT
// BOTTOM PANEL OF FIGURE 2
// This do file creates the plot from the regression model and the correspondning table for the appendix

// location of data -> be sure to replace directory location with your own directory before running!
cd "C:\Users\agooch\Dropbox\Working papers\War with China\data"
use War_with_China_Experiment_Gooch_cleaned
cd "C:\Users\agooch\Dropbox\Working papers\War with China\code"
//////////////////////////////////////////// 
// OUTREG TABLES FOR EACH OUTCOME MEASURE //
////////////////////////////////////////////


* Sample lincom two variables code
* local t1 : variable label `var1'
* local t2 : variable label `var2'
* qui lincom  `var1' -`var2'
* local fx = `r(estimate)'
* local tstat = abs(`r(estimate)'/`r(se)')
* local pvalue=ttail(`r(df)',`tstat')*2
* and 95% cI of lincom
* local  upperci= r(estimate) + invttail(r(df),0.025)*r(se)
* local lowerci = r(estimate) + invttail(r(df),0.975)*r(se)

////////////////////////////////////////////////////
// feeling thermometer with partisans broken out //
////////////////////////////////////////////////////

label var war_exp "Support for War with China (0-1)"

// the regression
reg Obama_favor cue_t1 Inevitable_t2 HumanRights_t3 Democrats Independents Turnout_VLikely Turnout_SLikely Northeast Midwest West Female Education Age AA Hispanic ///
Dem_Inevt_2 Dem_HR_3 Dem_cue_1 Ind_cue_1 Ind_Inevt_2 Ind_HR_3 

/* The following block of code makes the MFX plot */

/* Make all changes here: */

/* Graph Name for Export */
local graphfilename = "Ind_Obama_support"

/* Define Table Title Here */
local titletext = " "

/* Define note and caption text here. Note comes first. */
local notetext = "Non-response excluded, n=719. Plotted quantities are change in outcome relative to Control with 95% CI."


/* STARTING HERE, THIS BLOCK SHOULD REMAIN FIXED */

local outcomelab : variable label `e(depvar)'

gen _linctr=.
gen _lincomest=. 
gen _lincomtext=""
gen _lowerci=. 
gen _upperci=. 

local ctr=0
local tvar="cue_t1"
local tvar2="Ind_cue_1"
include 00_sub_doonevarlincomforgraph.do
local tvar="Inevitable_t2"
local tvar2="Ind_Inevt_2"
include 00_sub_doonevarlincomforgraph.do 
local tvar="HumanRights_t3"
local tvar2="Ind_HR_3"
include 00_sub_doonevarlincomforgraph.do 

labmask _linctr, values(_lincomtext)

qui summ _linctr
local ctrmin=r(min)
local ctrmax=r(max)
local rangemin=r(min)-.50
local rangemax=r(max)+.50

twoway (scatter _lincomest _linctr, mcolor(black) msymbol(circle) yscale(r(-0.2 0.2)) ylabel(#5) ) (rcap _lowerci _upperci _linctr, lcolor(black)), ytitle("Change in Obama Favorability Relative to Control", size(small) margin(right)) yline(0, lpattern(dash) lcolor(black)) xscale(range(`rangemin' `rangemax')) xtitle("") xlabel(`ctrmin'(1)`ctrmax', labels labsize(small) valuelabel) xmtick(none) title("Independents", size(small)) caption("`captiontext'", size(small) color(black) span) legend(off) scheme(s1mono) name("`graphfilename'", replace)
graph export "`graphfilename'.pdf", as(pdf) replace

capture drop _linctr _lincomest _lincomtext _lowerci _upperci
capture label drop _linctr

/* END FIXED BLOCK */
/* End MFX plot block */



























